home *** CD-ROM | disk | FTP | other *** search
- // This program creates a calendar. The data is taken from
- // a math-book.
- //
- // ranges:
- // century: 15 - 32
- // year: 0 - 99
- // month: 1 - 12
- // day: 1 - 31
- //
- // change user settings
- //
-
- int days[7][5]; int centurys[5][7]; int scenturys[4]; int years[7][18];
- int months[7][7]; int monthd[7][3]; int data[7][7];
-
- int century; int year; int month; int day; int dayname; int row; int col;
- int i; int j; int x; int ok; int data1; int data2; int leapyear;
- int ch1; int ch2;
- int monday; int tuesday; int wednesday; int thursday; int friday;
- int saturday; int sunday; int null;
-
-
- // calendar
-
- int monthlen[12]; int cal[12][42]; int cal2[12][7][6];
- int mstart; int cmonth; int cmonthpos; int cdays;
- int borderl; int bordert; int borderb; int borderm; int maxline;
-
-
- // USER SETTINGS --------------------------------------------------------
-
- maxline = 72; number of lines per page
- borderl = 8; left border
- bordert = 4; top border
-
- // DONT CHANGE ANYTHING BELOW! ------------------------------------------
-
- borderb = maxline -- bordert; borderb = borderb -- 47;
-
- monthlen[0] = 31; monthlen[1] = 28; monthlen[2] = 31;
- monthlen[3] = 30; monthlen[4] = 31; monthlen[5] = 30;
- monthlen[6] = 31; monthlen[7] = 31; monthlen[8] = 30;
- monthlen[9] = 31; monthlen[10] = 30; monthlen[11] = 31;
-
- string date[13]; string y[5]; string filen[13];
-
- #include <spl_date.dec>
- #include <datedata.n>
-
- lab start;
-
- leapyear = 0;
-
- print /n;
- ok = 0;
- while ok != 1;
- y = "";
- input "year: yyyy (RETURN to exit): " y;
- if y = ""; exit; endif;
- date = "01.01." + y;
- call spl_date (day, month, year, century, date);
- if day != -1;
- ch1 = year >= 0; ch2 = year <= 99;
- ok = ch1 and ch2;
- if ok != 1;
- print "year range: 0 - 99", /n;
- endif;
-
- ch1 = century >= 15; ch2 = century <= 32;
- ok = ch1 and ch2;
- if ok != 1;
- print "century range: 15 - 32", /n;
- endif;
- endif;
- wend;
-
- filen = "cal_" + y; filen = filen + ".txt";
-
- ok = 0;
- i = 0;
- while ok = 0;
- j = 0;
- while j <= 4;
- x = days[i][j];
- if x = day;
- row = i;
- ok = 1;
- endif;
- inc j;
- wend;
-
- if i < 6;
- inc i;
- endif;
- if i > 6;
- ok = 1;
- endif;
- wend;
-
-
- // check if leapyear
-
- i = 0;
- while i <= 3;
- x = scenturys[i];
- if x = century;
- if year = 0;
- leapyear = 1;
- endif;
- endif;
- inc i;
- wend;
-
- x = year mod 4;
- if x = 0;
- leapyear = 1;
- endif;
-
- ok = 0;
- i = 0;
- while ok = 0;
- j = 0;
- while j <= 2;
- x = monthd[i][j];
- if x = month;
- col = i;
- ok = 1;
- endif;
- inc j;
- wend;
-
- if i < 6;
- inc i;
- endif;
- if i > 6;
- ok = 1;
- endif;
- wend;
-
- if leapyear;
- if month = 1;
- col = 1;
- endif;
- if month = 2;
- col = 3;
- endif;
- endif;
-
- data1 = months[row][col];
-
- ok = 0;
- i = 0;
- while ok = 0;
- j = 0;
- while j <= 17;
- x = years[i][j];
- if x = year;
- row = i;
- ok = 1;
- endif;
- inc j;
- wend;
-
- if i < 6;
- inc i;
- endif;
- if i > 6;
- ok = 1;
- endif;
- wend;
-
- ok = 0;
- i = 0;
- while ok = 0;
- j = 0;
- while j <= 5;
- x = centurys[i][j];
- if x = century;
- col = j;
- ok = 1;
- endif;
- inc j;
- wend;
-
- if i < 4;
- inc i;
- endif;
- if i > 4;
- ok = 1;
- endif;
- wend;
-
- data2 = data[row][col];
- dayname = data1 + data2;
-
- ok = 0;
- i = 0;
- while ok = 0;
- j = 0;
- while j <= 4;
- x = days[i][j];
- if x = dayname;
- row = i;
- ok = 1;
- endif;
- inc j;
- wend;
-
- if i < 6;
- inc i;
- endif;
- if i > 6;
- ok = 1;
- endif;
- wend;
-
- dayname = row;
-
-
- // calendar - part
- // fill cal array
-
- init cal 0;
- cmonth = month -- 1;
-
- mstart = dayname -- 1;
- if dayname = sunday;
- mstart = 6;
- endif;
-
- while cmonth <= 11;
- cdays = monthlen[cmonth];
- if leapyear;
- if cmonth = 1;
- inc cdays;
- endif;
- endif;
-
- i = mstart; j = 1;
- while j <= cdays;
- cal[cmonth][i] = j;
- inc i;
- inc j;
- wend;
-
- if i > 34;
- mstart = 41 -- i;
- endif;
- if i <= 34;
- mstart = 34 -- i;
- endif;
- mstart = 6 -- mstart;
- inc cmonth;
- wend;
-
-
- // print calendar
- // copy to 2dimens for easy printing
-
- cmonth = 0;
- while cmonth <= 11;
- i = 0;
- col = 0;
- while col <= 5;
- row = 0;
- while row <= 6;
- day = cal[cmonth][i];
- cal2[cmonth][row][col] = day;
- inc i;
- inc row;
- wend;
- inc col;
- wend;
- inc cmonth;
- wend;
-
- print "writing to '", filen, "' ...", /n;
- fopen 1, filen, "w";
-
- fwrite 1, /n bordert;
- fwrite 1, /s borderl, /s30, century;
- if year <= 9;
- fwrite 1, null;
- endif;
- fwrite 1, year, /n3;
-
- borderm = borderl + 5;
-
- i = 1; cmonthpos = 0;
- while i <= 4;
- if i = 1;
- fwrite 1, /s borderm, "January", /s12, "February", /s11, "March", /n2;
- goto endm;
- endif;
- if i = 2;
- fwrite 1, /s borderm, "April", /s14, "May", /s16, "June", /n2;
- goto endm;
- endif;
- if i = 3;
- fwrite 1, /s borderm, "July", /s15, "August", /s13, "September", /n2;
- goto endm;
- endif;
- if i = 4;
- fwrite 1, /s borderm, "October", /s12, "November", /s11, "December", /n2;
- endif;
-
- lab endm;
-
- row = 0;
- while row <= 6;
- fwrite 1, /s borderl;
-
- if row = 0; fwrite 1, "mon"; goto endd; endif;
- if row = 1; fwrite 1, "tue"; goto endd; endif;
- if row = 2; fwrite 1, "wed"; goto endd; endif;
- if row = 3; fwrite 1, "thu"; goto endd; endif;
- if row = 4; fwrite 1, "fri"; goto endd; endif;
- if row = 5; fwrite 1, "sat"; goto endd; endif;
- if row = 6; fwrite 1, "sun"; endif;
-
- lab endd;
-
- fwrite 1, "|";
-
- j = 1;
- cmonth = cmonthpos;
- while j <= 3;
- col = 0;
- while col <= 5;
- day = cal2[cmonth][row][col];
- if day > 0;
- if day <= 9;
- fwrite 1, /s;
- endif;
- fwrite 1, day;
- goto nextcol;
- endif;
- fwrite 1, /s2;
-
- lab nextcol;
-
- fwrite 1, /s;
- inc col;
- wend;
- fwrite 1, "|";
- inc j;
- inc cmonth;
- wend;
- fwrite 1, /n;
- inc row;
- wend;
- fwrite 1, /n2;
- inc i;
- cmonthpos = cmonthpos + 3;
- wend;
- fwrite 1, /n borderb;
- fclose 1;
- exit;
-
- #include <spl_date.sub>
-
-